# -*- coding: utf-8 -*-
"""
@Time: 2021/12/23 10:22
@Author: jins
@File: table_powerfactord.py
@Introduction: powerfactord表造数据
"""
from common.mysqlDataOperate import OperateMysql
import random
from datetime import datetime, timedelta

PhaseOptions_list = [1, 2, 4, 8]


def insert(start):
    op = OperateMysql()
    for j in range(start + 1, start + 3):
        for k in PhaseOptions_list:
            data_time = datetime(2019, 11, 1, 0, 0, 0)
            fmt = '%Y%m%d'
            for i in range(30):
                DateNum = int(data_time.strftime(fmt))
                device_id = 10000000 + j
                UpdateTime = data_time.timestamp() * 1000
                MaxValue = random.uniform(200.0, 250.0)
                MaxTimeNum = int(data_time.strftime(fmt))
                MinValue = random.uniform(50.0, 100.0)
                MinTimeNum = int(data_time.strftime(fmt))
                AvgValue = random.uniform(150.0, 300.0)
                MaxMinDiff = MaxValue - MinValue
                MaxMinDiffRatio = MaxMinDiff / AvgValue
                AvgRatio = random.uniform(0.0, 1.0)
                UpperUpperTimes = random.randint(100, 150)
                UpperUpperCount = random.randint(0, 10)
                UpperTimes = random.randint(100, 150)
                UpperCount = random.randint(0, 10)
                LowerTimes = random.randint(100, 150)
                LowerCount = random.randint(0, 10)
                LowerLowerTimes = random.randint(100, 150)
                LowerLowerCount = random.randint(0, 10)
                sql = f"""INSERT INTO xlcloud.powerfactord19b
                VALUES
                    (   
                        {DateNum},
                        {device_id},
                        {k},
                        {MaxValue},
                        {MaxTimeNum},
                        {MinValue},
                        {MinTimeNum},
                        {AvgValue},
                        {MaxMinDiff},
                        {MaxMinDiffRatio},
                        {AvgRatio},
                        {UpperUpperTimes},
                        {UpperUpperCount},
                        {UpperTimes},
                        {UpperCount},
                        {LowerTimes},
                        {LowerCount},
                        {LowerLowerTimes},
                        {LowerLowerCount},
                        1,
                        1,
                        {UpdateTime}
                     )
                        """
                op.batch_excute(sql)
                data_time += timedelta(days=1)
            op.commit()
    op.close()


if __name__ == '__main__':
    insert(0)